package thirdassigment;

import java.io.File;
import java.io.FileInputStream;
//import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Move implements ICommandExecutor {
	private static ICommandExecutor instance;
	public void execute(String enterstr) throws IOException{
		String[] StrArray = enterstr.split(" ");
		String file1 = StrArray[1];
		String file2 = StrArray[2];
		
	    FileInputStream f1 = new FileInputStream(file1);
		FileOutputStream f2 = new FileOutputStream(file2);
		
				fileCopyMove(f1, f2);
				
				 File file = new File(file1);
				    file.delete();
		
	}
	public static void fileCopyMove(InputStream in, OutputStream out) throws IOException
			{
			  int nLength;
			  byte[] buf = new byte[8000];
			  while(true)
			  {
			    nLength = in.read(buf);
			      if(nLength < 0){ 
			        break;
			      }
			    out.write(buf, 0, nLength);
			  }
			       
			  in.close();
			  out.close();
			}
	
	private Move(){
	}
	public static ICommandExecutor getInstance() {
	    if(instance==null){
	            instance=new Move();       
	            }
	    return instance;
	}
	}

